//
//  ServiceViewController.m
//  HZZFAdSDK_Example
//
//  Copyright © 2025 早范. All rights reserved.
//

#import "ServiceViewController.h"
#import <HZZFAdSDK/HZZFAdSDKServiceAdView.h>
@interface ServiceViewController ()<HZZFSDKServiceAdViewDelegate>
@property (nonatomic)HZZFAdSDKServiceAdView *serviceAdView;
@end

@implementation ServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"非标";
    CGFloat width = (self.view.frame.size.width - 150) / 2;
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(width, 150, 150, 40);
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor orangeColor];
    btn.layer.cornerRadius = 20;
    [self.view addSubview:btn];
    [btn setTitle:@"显示广告" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor blackColor] forState:0];
    [btn addTarget:self action:@selector(loadServiceAd) forControlEvents:UIControlEventTouchUpInside];
}
- (void)loadServiceAd{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIViewController *rvc = window.rootViewController;
    _serviceAdView = [[HZZFAdSDKServiceAdView alloc] initWithFrame:CGRectMake(self.view.center.x-50,self.view.center.y, 100,100)];
    
    _serviceAdView.delegate = self;
    _serviceAdView.controller = rvc;
    _serviceAdView.refershTime = 35;
    _serviceAdView.posId = @"57229709";
    _serviceAdView.showCloseView = YES;
    _serviceAdView.backgroundColor = [UIColor clearColor];
    // 查看价格，需要在设置广告位id之后调用
//    NSLog(@"price----%ld", [_serviceAdView getBidPrice]);
    // 发送竞价失败上报，此时的价格为第三方赢价的价格
    // [_serviceAdView sendLossNotice:100];
    // 发送竞价成功上报
//    [_serviceAdView sendWinNotice:100];
    // 2 添加到父视图上
//    _serviceAdView.frame = CGRectMake(0, 200, 350, 150);
//    [rvc.view addSubview:_serviceAdView];
    // 3 加载并显示广告
    [_serviceAdView loadAndShow];
    
}
/**
广告获取成功
@param serviceAdView 广告实例
*/
- (void)HZZF_serviceAdViewDidReceived:(HZZFAdSDKServiceAdView *)serviceAdView{
    // 3 加载并显示广告 注意: 请确保banner视图显示在屏幕内的时候,调用load方法
    [self.view addSubview:serviceAdView];
}

/**
广告拉取失败
@param serviceAdView 广告实例
@param error 错误描述
*/
- (void)HZZF_serviceAdViewFailToReceived:(HZZFAdSDKServiceAdView *)serviceAdView
error:(NSError *)error{
    NSString *message = @"广告渲染失败了";

   
}


/**
广告点击
@param serviceAdView 广告实例
@param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
*/
- (void)HZZF_serviceAdViewClicked:(HZZFAdSDKServiceAdView *)serviceAdView
loadingPageURL:(NSString *)loadingPageURL{

}


/**
广告关闭
@param serviceAdView 广告实例
 */
- (void)HZZF_serviceAdViewClose:(HZZFAdSDKServiceAdView *)serviceAdView{
    
 
}

/**
广告展示
@param serviceAdView 广告实例
*/
- (void)HZZF_serviceAdViewExposure:(HZZFAdSDKServiceAdView *)serviceAdView{

}

- (void)HZZF_serviceAdViewClickedReport:(nonnull HZZFAdSDKServiceAdView *)serviceAdView { 
    
}


- (void)HZZF_serviceAdViewCloseLandingPage:(nonnull HZZFAdSDKServiceAdView *)serviceAdView { 
    
}


- (void)HZZF_serviceAdViewExposureReport:(nonnull HZZFAdSDKServiceAdView *)serviceAdView { 
    
}

@end
